package com.fesco.mis.fm.controller;


import com.fesco.mis.fm.constant.FmWebConstant;
import com.fesco.mis.fm.exception.ControllerException;
import com.fesco.mis.fm.exception.ExceptionEnum;
import com.fesco.mis.fm.model.BaseDict;
import com.fesco.mis.fm.service.BaseDictService;
import com.fesco.mis.fm.util.voutils.ResponseResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <descption>示例controller</descption>
 * @date ：2017/9/2 16:25
 * @author：梅海波<meihaibo13186@sinosoft.com.cn>
 * @version:0.1
 */
@RestController
@RequestMapping(FmWebConstant.SERVICE_NAME)
public class FmDemoController {

    /**
     * 注入属性 service
     */
    @Autowired
    private BaseDictService baseDictService;


    /**
     *
     * @param baseDict
     * @return ResponseResult
     * <descption>访问方式 get
     * </descption>
     * @date ：2017/9/4 11:26
     * @author：梅海波<meihaibo13186@sinosoft.com.cn>
     * @version:0.1
     */
    @GetMapping(FmWebConstant.HELLO_DICT_GET)
    public ResponseResult helloDictGet(BaseDict baseDict){
        baseDict = baseDictService.selectByPrimaryKey(42304L);
        ResponseResult result = new ResponseResult();
        result.setData(baseDict);
        return result;
    }

    @PostMapping(FmWebConstant.HELLO_DICT_POST)
    public ResponseResult helloDictPost(@RequestBody BaseDict baseDict){
        if(baseDict.getDictId().longValue() == 100){
            throw new ControllerException(ExceptionEnum.DATABASE_FAILURE);
        }
        PageInfo pageInfo = baseDictService.getDictList(baseDict);
        ResponseResult result = new ResponseResult();
        result.setData(pageInfo);
        return result;
    }


    @GetMapping(FmWebConstant.HELLO)
    public ResponseResult<String> hello(){
        ResponseResult result = new ResponseResult();
        result.setData("hello World");
        return result;
    }



}
